package com.blog.controller;

import com.blog.common.CommonRespDto;

import com.blog.seckill.address.SecAddress;
import com.blog.service.SecAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @ClassName SecAddressController
 * @Destription 店铺信息
 * @Author 天堂小野花
 * @Date 2025/7/21  14:49
 * @Version 1.0
 */
@RestController
@RequestMapping("/address")
public class SecAddressController {
    @Autowired
    SecAddressService secAddressService;
    @GetMapping("/initSecAddress")
    public CommonRespDto initSecAddress(){
        List<SecAddress> listAddress = secAddressService.initSecAddress();
        return CommonRespDto.success(listAddress);
    }
    @GetMapping("/initSecBusi")
    public CommonRespDto initSecBusi(){
        List<Map<Integer,String>> listBusi =secAddressService.initSecBusi();
        List<Map<Integer,String>> listState =secAddressService.initSecState();
        Map<String, Object> map = new HashMap<>();
        map.put("listBusi",listBusi);
        map.put("listState",listState);
        return CommonRespDto.success(map);
    }
    @PostMapping("/addAddress")
    public CommonRespDto addAddress(@RequestBody SecAddress secAddress){
        System.out.println(secAddress);
        if(secAddressService.addAddress(secAddress) ==1){
            return  CommonRespDto.success("添加成功");
        }
        return CommonRespDto.error("添加失败");
    }
    @PutMapping("/saveAddress")
    public CommonRespDto saveAddress(@RequestBody SecAddress secAddress){
        if (secAddressService.saveAddress(secAddress)==1){
            return CommonRespDto.success("更新成功");
        }
        return CommonRespDto.error("更新失败");
    }
    @GetMapping("/god/init")
    public CommonRespDto initGod(){
        //高德地图web服务端的代码无需启用，仅仅测试对接成功即可
        //secAddressService.initGod();
        return CommonRespDto.success();
    }
}
